//
//  NSString+Crash.m
//  flutter
//
//  Created by GilesZhou on 2020/6/28.
//  Copyright © 2020 Ganee. All rights reserved.
//

#import "NSString+Crash.h"
#import "CrashManager.h"

@implementation NSString (Crash)

+ (void)ch_observeCrash {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class __NSCFConstantString = NSClassFromString(@"__NSCFConstantString");
        
        [CrashManager exchangeInstanceMethod:__NSCFConstantString method1Sel:@selector(stringByAppendingString:) method2Sel:@selector(ch_stringByAppendingString:)];
    });
    
}

- (NSString *)ch_stringByAppendingString:(NSString *)aString {
    NSString *result = @"";
    
    @try {
        result = [self ch_stringByAppendingString:aString];
    } @catch (NSException *exception) {
        UncaughtExceptionHandler(exception);
    } @finally {
        return result;
    }
}

@end
